package io.bloom.webspider;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

public class SpiderLinkMatcher
{
    private List<Pattern> patterns = new ArrayList<Pattern>();

    public static SpiderLinkMatcher of(String... pattern)
    {
        SpiderLinkMatcher matcher = new SpiderLinkMatcher();
        for (String s : pattern)
        {
            matcher.patterns.add(Pattern.compile(s));
        }

        return matcher;
    }

    public boolean match(String link)
    {

        if (patterns.size() == 0)
        {
            return true;
        }
        for (Pattern pattern : patterns)
        {
            if (pattern.matcher(link).matches())
            {
                return true;
            }
        }
        return false;

    }
}
